// 获取切换按钮和要切换的内容元素
const btn1 = document.querySelector('.ty');
const btn2 = document.querySelector('.cp');
const hiddenContent = document.querySelector('#hiddenContent');
const cpContent = document.querySelector('#cpContent');

// 给第一个切换按钮添加点击事件监听器
btn1.addEventListener('click', function() {
    // 切换隐藏的内容的显示状态
    hiddenContent.style.display = 'flex';
    cpContent.style.display = 'none';
});

// 给第二个切换按钮添加点击事件监听器
btn2.addEventListener('click', function() {
    // 切换隐藏的内容的显示状态
    hiddenContent.style.display = 'none';
    cpContent.style.display = 'flex';
});
document.addEventListener('DOMContentLoaded', function() {
    const dropdownBtns = document.querySelectorAll('.dropdown-btn');
    dropdownBtns.forEach(btn => {
        btn.addEventListener('click', function(event) {
            const dropdownContent = this.nextElementSibling;
            // 隐藏所有其他下拉菜单
            const allDropdowns = document.querySelectorAll('.dropdown-content');
            allDropdowns.forEach(dropdown => {
                if (dropdown !== dropdownContent && dropdown.classList.contains(
                        'show')) {
                    dropdown.classList.remove('show');
                }
            });
            dropdownContent.classList.toggle('show');
            event.stopPropagation(); // 阻止事件冒泡到window的click事件监听器

            // 改变按钮颜色
            dropdownBtns.forEach(btn => {
                if (btn === this) {
                    btn.classList.add('active'); // 添加active类来改变按钮颜色
                } else {
                    btn.classList.remove('active'); // 移除active类恢复按钮原有颜色
                }
            });
        });
    });
});

// 获取左右切换按钮的DOM元素
const height = document.getElementById('height');
const leftToggleBtn = document.getElementById('left-toggle');
const rightToggleBtn = document.getElementById('right-toggle');
var po = document.getElementById("position");

function toggleButtons(leftButton, rightButton) {
    leftButton.style.display = 'none';
    rightButton.style.display = 'block';
}
leftToggleBtn.addEventListener('click', function() {
    toggleButtons(leftToggleBtn, rightToggleBtn);
    height.style.transition = "0.5s";
    height.style.width = "0px";
    // 在过渡效果结束后执行显示/隐藏操作
    height.addEventListener("transitionend", function() {
        if (height.style.width === "0px") {
            po.style.display = 'block';
        }
    });
});
rightToggleBtn.addEventListener('click', function() {
    toggleButtons(rightToggleBtn, leftToggleBtn);
    height.style.transition = "0.5s";
    height.style.width = "200px";
    if (height.style.width !== "0px") {
        po.style.display = 'none';
    }
});
// // 如果用户点击菜单以外的地方，则关闭下拉菜单
// window.addEventListener('click', function () {
//     const dropdowns = document.querySelectorAll('.dropdown-content');
//     dropdowns.forEach(dropdown => {
//         if (dropdown.classList.contains('show')) {
//             dropdown.classList.remove('show');
//         }
//     });
// });
//当天日期
function showPage(url) {
    var iframe = document.getElementById("myFrame");
    iframe.src = url;
    return false; // 阻止 <a> 标签的默认行为
}

function getCurrentDate() {
    var now = new Date();
    var year = now.getFullYear();
    var month = ("0" + (now.getMonth() + 1)).slice(-2); // 注意月份从0开始，需要加1
    var day = ("0" + now.getDate()).slice(-2);

    // 构建日期格式字符串
    var currentDate = "今天是" + year + "年" + month + "月" + day + "日";
    // 更新页面上的日期显示
    document.getElementById('current-date').textContent = currentDate;
}
window.onload = getCurrentDate;